<?xml version="1.0" encoding="utf-8"?>
<taskrunner name="remove.files" version="1.2" date="2008-10-27" maxthreads="1">

  <!-- Script för avinstallation 
  
    log:
      2008-12-05/MMA  Added task remove.vidasave. Run only wheen INSTALL_TYPE = REINSTALL
                      Task movetovidasave run only when install.type = UNINSTALL
                      
      2009-03-19/MMA  Task "delete.shortcuts" will not be run if main.install.type="REINSTALL"
                      Shortcuts should not be removed!
                      
      CR3904 : 2012-03-07 : teriks28
        Added task "uninstall.sqlexpress", moved from installshield because SQL Express 2008 did not like installshields uninstall
                      
    Dependencies:
      Global property install.type must be set to either UNINSTALL or REINSTALL
  -->
  
  
  <includes>
    <file name="vida.install.settings.xml" />
  </includes>

  <tasks>

    <task name="start.sqlexpress.service" critical="false" typename="@WindowsServiceCommand">
      <description>
        starts sql express instance if it's already installed.
      </description>
      <dependencies list=""/>
      <parameters>
        <parameter name="server.name" value=""/>
        <parameter name="service.name" value="MSSQL$${sqlserver.instance.name}"/>
        <parameter name="command" value="start"/>
      </parameters>
    </task>

    <task name="accessserver.is.attached" critical="false" typename="@SqlServerManagement.IsDatabaseAttached" run="${run.accessserver.is.attached}">
      <dependencies list="start.sqlexpress.service"/>
      <parameters>
        <parameter name="server" value="${sqlserver.local.server}"/>
        <parameter name="userid" value="${sqlserver.local.userid}"/>
        <parameter name="password" value="${sqlserver.local.password}"/>
        <parameter name="database" value="${db.accessserver.name}"/>
        <!-- out parameters -->
        <parameter name="output.value" value="accessserver.is.attached"/>

      </parameters>
    </task>
    
    <task name="remove.installed.updates" condition="¤{accessserver.is.attached}=true" critical="false" typename="@SqlServer.Execute">
      <description>
        Delete all records in the AccessServer table InstalledUpdate.
      </description>
      <dependencies list="accessserver.is.attached"/>
      <parameters>
        <parameter name="command" value="delete from InstalledUpdate"/>
        <parameter name="timeout" value="0"/>
        <parameter name="connectionstring" value="${accessserver.cs}"/>
      </parameters>
    </task>
    
    <task name="detach.all.databases" critical="true" retry="3" typename="@SqlServerManagement.DetachAllDatabases">
      <dependencies list="start.sqlexpress.service,remove.installed.updates[requiresuccess=false]"/>
      <parameters>
        <parameter name="server" value="${sqlserver.local.server}"/>
        <parameter name="userid" value="${sqlserver.local.userid}"/>
        <parameter name="password" value="${sqlserver.local.password}"/>
      </parameters>
    </task>

    <task name="stop.sqlexpress.service" critical="false" typename="@WindowsServiceCommand">
      <description>
        stops sql express instance if it's already installed.
      </description>
      <dependencies list="detach.all.databases"/>
      <parameters>
        <parameter name="server.name" value=""/>
        <parameter name="service.name" value="MSSQL$${sqlserver.instance.name}"/>
        <parameter name="command" value="stop"/>
      </parameters>
    </task>
    
    <task name="uninstall.sqlexpress" critical="false" condition="¤{main.install.type}=UNINSTALL">
      <description>
        If UNINSTALL then unistall SQL express.
        This task will not be ran when main.install.type is REINSTALL!!
      </description>
      <dependencies list="stop.sqlexpress.service"/>
      <subtasks filename="vida.uninstall.sqlserver.xml"/>     
    </task>

    <task name="remove.autostart">
      <dependencies list=""/>
      <subtasks filename="vida.autostart.xml"/>
    </task>

    <task name="delete.shortcuts">
      <description>
        Desktop shortcuts will not be removed if main.install.type = REINSTALL. The shortcuts
        for VIDA Admin and VIDA on Web is set by an external program and if we remove the shortcuts
        then they will point to the wrong target after the reinstall.
      </description>
      <dependencies list=""/>
      <subtasks filename="vida.install.desktop.shortcuts.xml"/>
    </task>

    <task name="check.vidadb.dir" typename="@DirectoryExists">
      <parameters>
        <parameter name="directory" value="${target.db.dir}"/>
        <parameter name="output.value" value="vidadb.dbdir.exists"/>
      </parameters>
    </task>

    <task name="kill.systemprocesses">
      <dependencies list=""/>
      <description>
        Terminates the process Vidamonitor.
      </description>
      <subtasks filename="vida.kill.systemprocesses.xml"/>
    </task>

    <task name="moveto.vidasave" condition="¤{main.install.type}=REINSTALL">
      <description>
        If REINSTALL then some files will be saved in the vidasave directory to make it easier when the
        user installs vida the next time. This is, however, by some people not considered to be a good ideá. 
        A better way could be to issue a question to the user if he/she wants the files to be saved so they could
        be used in a subsequent installation. 
      </description>
      <dependencies list="kill.systemprocesses,detach.all.databases"/>
      <subtasks filename="vida.moveto.vidasave.xml"/>
    </task>

    <task name="remove.vidasave" typename="@DeleteDirectory" condition="¤{main.install.type}=UNINSTALL">
      <description>
        If UNINSTALL then the content of the vidasave directory must be deleted. 
        This task will not be ran when main.install.type is REINSTALL!!
      </description>
      <dependencies list="stop.sqlexpress.service"/>
      <parameters>
        <parameter name="directory" value="${target.vidasave.dir}"/>
      </parameters>
    </task>
    
    <task name="remove.systemfiles">
      <description>
        Remove a set of system files.
      </description>
      <dependencies list="kill.systemprocesses,remove.vidasave[requireSuccess=false]"/>
      <subtasks filename="vida.remove.system.files.xml"/>
    </task>

    <task name="delete.backup.eUpdate.dir" critical="false"  typename="@DeleteDirectory">
      <dependencies list="remove.installed.updates"/>
      <description>
        Deletes all previously stored eUpdates backups, if not a REINSTALL.
      </description>
      <parameters>
        <parameter name="directory" value="${target.uninstall.eUpdate.dir}"/>
      </parameters>
    </task>

    <task name="delete.db" condition="¤{vidadb.dbdir.exists}=true" critical="false" typename="@DeleteDirectory">
      <dependencies list="stop.sqlexpress.service,moveto.vidasave,check.vidadb.dir"/>
      <parameters>
        <parameter name="directory" value="${target.db.dir}"/>
      </parameters>
    </task>

    <task name="delete.jboss">
      <dependencies list="kill.systemprocesses,moveto.vidasave"/>
      <subtasks filename="vida.remove.jboss.xml"/>
    </task>

    <task name="delete.root.deploy.dir" typename="@DeleteDirectory">
      <dependencies list="kill.systemprocesses,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.root.deploy.dir}"/>
      </parameters>
    </task>

    <task name="delete.root.utils.dir" typename="@DeleteDirectory">
      <dependencies list="delete.jboss,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.root.utils.dir}"/>
      </parameters>
    </task>

    <task name="delete.eUpdate.dir" critical="false" typename="@DeleteDirectory">
      <dependencies list="delete.jboss,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.eUpdate.app.dir}"/>
      </parameters>
    </task>

    <task name="delete.eUpdate.unzip.dir" critical="false" typename="@DeleteDirectory">
      <dependencies list="delete.jboss,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.eupdate.unzip.dir}"/>
      </parameters>
    </task>

    <task name="delete.eUpdate.inbox.dir" critical="false" typename="@DeleteDirectory">
      <dependencies list="delete.jboss,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.eupdate.inbox.dir}"/>
      </parameters>
    </task>

    <task name="delete.system.config.dir" critical="false" typename="@DeleteDirectory">
      <dependencies list="delete.jboss,moveto.vidasave"/>
      <parameters>
        <parameter name="directory" value="${target.root}\System\Config"/>
      </parameters>
    </task>

  </tasks>
</taskrunner>